﻿toggle = function (fsid)
{
    var div = $id("div_" + fsid);
    var lnkdscd = $id("lnkdscd__lov_" + fsid);
    var lnkedit = $id("lnkedit__lov_" + fsid);
    var display = "";
    
    if( div.style.display != "none" )
    {
        display = "none";
    }
    
    div.style.display = display;
    if(lnkdscd != null)
    {
        lnkdscd.style.display = display;
    }
    if(lnkedit != null)
    {
        lnkedit.style.display = display;
    }
    
    
}
FilterTema = function()
{
    var lovhTema = $id("lovh_UFT.FILTERTEMA");
    var eventID = lovhTema.value;
    dgGuest_Invitation_c.PerformCallback("FILTER" + DELIMITER + eventID);
}
All = function()
{
    var lovhTema = $id("lovh_UFT.FILTERTEMA");
    var lovTema = $id("lov_UFT.FILTERTEMA");
    lovhTema.value = "";
    lovTema.value = "";
    dgGuest_Invitation_c.PerformCallback("ALL");
}
DoReject = function(invId, reason){
//    var btnReject = $id("btnReject");
//    var btnSubmit = $id("btnSubmit");
//    var load = $id("load");
    var reason = $id("reasonEditor");
    var hf = $id("hfDisplay");
    if(confirm("Reject Invitations?"))
    {
    hf.InnerHTML = "REJECT";
//    btnReject.style.display = "none";
//    btnSubmit.style.display = "none";
//    load.innerHTML = "<img src='" + LOADING.src + "' alt='' />";
    dgGuestList_c.PerformCallback("REJECT" + DELIMITER + invId + DELIMITER + reason.value);
    } 
}
DoSubmit = function()
{
    //var btnReject = $id("btnReject");
    var btnSubmit = $id("btnSubmit");
    var load = $id("load");
    var hf = $id("hfDisplay");
    var emailType = $id("UFT.EMAILTYPE");
	var tipe = emailType.value;
    if(confirm("Send email?"))
    {
        hf.InnerHTML = "SUBMIT";
        //btnReject.style.display = "none";
        btnSubmit.style.display = "none";
        load.innerHTML = "<img src='" + LOADING.src + "' alt='' />";
        closeChooseEmail();
        cbkInvite_c.PerformCallback("SUBMIT" + DELIMITER + tipe);
    }
}
NotSend = function()
{
    closeChooseEmail();
    var btnSubmit = $id("btnSubmit");
    var load = $id("load");
    btnSubmit.style.display = "none";
    load.innerHTML = "<img src='" + LOADING.src + "' alt='' />";
    cbkInvite_c.PerformCallback("SUBMIT" + DELIMITER + "NOTSEND");
}
SubmitChooseEmail = function()
{
    var div = $id("popuplayer");
    div.style.display = "block";
    div.innerHTML = "<img src='" + LOADING.src + "' alt='' />";
    renderFirst();
    
    cbkInvite_c.PerformCallback("EMAIL"); 
}
RejectGuest = function(invitationId, custId)
{
    var div = $id("popuplayer");
    div.style.display = "block";
    div.innerHTML = "<img src='" + LOADING.src + "' alt='' />";
    renderFirst();
    
    cbkInvite_c.PerformCallback("REJECT" + DELIMITER + invitationId + DELIMITER + custId); 
}
DoSubmitReason = function(invID, custId)
{
//ambil data
    var reason = $id("lovh_UFT.REASON").value;
    //alert(reason);
    if(confirm("Simpan alasan?"))
    {
        cbkInvite_c.PerformCallback("REASONSUBMIT" + DELIMITER + invID + DELIMITER + reason + DELIMITER + custId);        
    }
}
Reason = function()
{
    //do nothing
}
//InviteGuestzzz = function(invitationId, companyId){
//    var div = $id("popuplayer");
//    div.style.display = "block";
//    div.innerHTML = "<img src='" + LOADING.src + "' alt='' />";
//    renderFirst();
//    
//    cbkInvite_c.PerformCallback("INVITE" + DELIMITER + companyId + DELIMITER + invitationId);    
//}
InviteGuest = function(invitationId, companyId){
    var div = $id("popupGuest");
    var hfInvID = $id("hfInvID");
    var hfCompID = $id("hfCompID");
    hfInvID.value = invitationId;
    hfCompID.value = companyId;
    div.style.display = "block";
    dgGuest_c.PerformCallback("INIT" + DELIMITER + invitationId + DELIMITER + companyId);
    dgGuestSelected_c.PerformCallback("INIT" + DELIMITER + invitationId + DELIMITER + companyId);
}
DoCancelGuest = function()
{
    var div = $id("popupGuest");
    var hfInvID = $id("hfInvID");
    var hfCompID = $id("hfCompID");
    hfInvID.value = "";
    hfCompID.value = "";
    div.style.display = "none";
    dgGuest_c.SetVisible(false);
    dgGuestSelected_c.SetVisible(false);
    dgGuestList_c.PerformCallback("");
}
DoSelectGuest = function()
{
    var hfInvID = $id("hfInvID");
    var hfCompID = $id("hfCompID");
    invitationId = hfInvID.value;
    companyId = hfCompID.value;
    dgGuestSelected_c.PerformCallback("SELECT" + DELIMITER + invitationId + DELIMITER + companyId);
}
checkAll = function()
{
    dgGuest_c.SelectAllRowsOnPage();
}
uncheckAll = function()
{
    dgGuest_c.UnselectAllRowsOnPage();
}
checkAll2 = function()
{
    dgGuest_Invitation_c.SelectAllRowsOnPage();
}
uncheckAll2 = function()
{
    dgGuest_Invitation_c.UnselectAllRowsOnPage();
}
dgGuest_c_CallbackComplete = function()
{
    dgGuest_c.SetVisible(true);
    dgGuestSelected_c.SetVisible(true);
}
dgGuestSelected_c_CallbackComplete = function()
{
    uncheckAll();
}
cbkInvite_c_CallbackComplete = function(e){
    if( e.parameter.startsWith("REJECT"))
    {
        var div = $id("popuplayer");
        div.innerHTML = e.result;
    }
    else if( e.parameter.startsWith("EMAIL"))
    {
        var div = $id("popuplayer");
        div.innerHTML = e.result;
    }
    else if (e.parameter.startsWith("SUBMIT"))
    {
        closeChooseEmail();
        window.location = "UFTList.aspx?mode=submitted";
        //dgGuestList_c.PerformCallback("SUBMIT");
    }
    else if (e.parameter.startsWith("REASONSUBMIT"))
    {
        closeReason();
        //window.location = "UFTList.aspx?mode=submitted";
        dgGuestList_c.PerformCallback("REFRESHREASON");
    }
}
dgGuestList_c_CallbackComplete = function(e){

    
    var hf = $id("hfDisplay");
    if(hf.InnerHTML == "REJECT")
    {
//        reject.style.display = "inline";
//        submit.style.display = "inline";
//        load.style.display = "none";
    }
    else if(hf.InnerHTML == "SUBMIT")
    {
        //var reject = $id("btnReject");
        var submit = $id("btnSubmit");
        var load = $id("load");
        //reject.style.display = "none";
        submit.style.display = "none";
        load.style.display = "none";
    }
    
}
closeGuestInvitation = function(){
    var div = $id("popuplayer");
    div.innerHTML = "";
    div.style.display = "none";
}
closeChooseEmail = function()
{
    var div = $id("popuplayer");
    div.innerHTML = "";
    div.style.display = "none"; 
}
closeReason = function()
{
    var div = $id("popuplayer");
    div.innerHTML = "";
    div.style.display = "none";
}
inviteMore = function(companyId)
{
    var hf = $id("hf.guestcount");
    var invId = $id("hf.invitationid");
    cbkInvite_c.PerformCallback("MORE" + DELIMITER + companyId+ DELIMITER + invId.innerHTML + DELIMITER + hf.innerHTML);    
}

saveGuestInvitation = function(companyId)
{
    if(confirm("save guests?"))
    {
        var load = $id("load_"+companyId);
        // di sini kirim data perubahannya
        var input = getGuestData(companyId);
        //alert(input);
        load.innerHTML = "<img src='" + LOADING.src + "' alt='' />"; 
        cbkInvite_c.PerformCallback(input);
    }
}
getGuestData = function(companyId)
{
    //alert(companyId);
    var invId = $id("hf.invitationid");
    var inputs = $nm("txt");
    var output = "SAVE" + DELIMITER + companyId + DELIMITER + invId.innerHTML + DELIMITER;
    
    for( var i=0; i < inputs.length; i++ )
    {
        if( i > 0 )
        {
            output += DELIMITER;
        }
        
        var item = inputs[i];
        var lov = $id("lov_" + item.id);
        
        if( lov == null )
        {
            output += item.id + NEWLINE + item.value;
        }
        else
        {
            var lovh = $id("lovh_" + item.id);
            output += lov.value + NEWLINE + lovh.value + NEWLINE + item.value;        
        }
    }
    //alert(output);
    return output;
    
}

checkRE = function(invId)
{
var txt = $id("reasonEditor");
alert(invId + " --- " + txt.value);
}

ShowSelectedContactData = function()
{
    // do nothing
}



DoSelect = function(){
    dgGuest_Invitation_c.PerformCallback("select");
    $id("hfSelect").value = "Y";
}
dgGuest_Invitation_c_EndCallBack = function(e){
    var hf = $id("hfSelect");
    if(hf.value == "Y")
    {
        //dgSelected_Invitation_c.PerformCallback("refresh");
        dgGuestList_c.PerformCallback("");
    }
    
    hf.value = "";    
}

//DoSubmit2 = function(){
//    var load = $id("loadSubmit2");
//    var link = $id("btnSubmit2");
//    
//    link.style.display = "none";
//    load.innerHTML = "<img src='" + LOADING.src + "' alt='' />";
//    
//    cbkInvitation_c.PerformCallback("");
//}
//cbkInvitation_c_CallbackComplete = function(e) {
//    //window.location = "UFTList.aspx?mode=submitted";
//    dgGuestList_c.PerformCallback("");
//}
//cbkInvitation_c_CallbackError = function(e) {
//    var load = $id("loadSubmit2");
//    var link = $id("btnSubmit2");
//    
//    link.style.display = "block";
//    load.innerHTML = ""; 
//}